package com.burstly.lib.currency.request;

import android.os.Handler;
import android.os.Looper;
import com.burstly.lib.currency.AccountInfo;
import com.burstly.lib.currency.UserAccount;
import com.burstly.lib.currency.secured.SecuredRequestBuilder;
import com.burstly.lib.currency.secured.SecuredServiceRequest;
import com.burstly.lib.network.request.CurrencyRequestTask;
import com.burstly.lib.util.LoggerExt;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

class RequestLinkAccountRunnable
  implements Runnable
{
  static final LoggerExt LOG = LoggerExt.getInstance();
  static final int MS_IN_SEC = 1000;
  static final String OK_SERVER_CODE = "0";
  static final String TAG = RequestLinkAccountRunnable.class.getSimpleName();
  static final String USER_NOT_FOUND_CODE = "2";
  final UserAccount mAccount;
  final AtomicInteger mDelayTime = new AtomicInteger(10);
  final AccountInfo mNewAccount;
  boolean mTryInactiveAccounts;
  final Handler mUIHandler = new Handler(Looper.getMainLooper());

  RequestLinkAccountRunnable(UserAccount paramUserAccount, AccountInfo paramAccountInfo)
  {
    this.mAccount = paramUserAccount;
    this.mNewAccount = paramAccountInfo;
  }

  LinkAccountRequest prepareRequest(AccountInfo paramAccountInfo)
  {
    LinkAccountRequest localLinkAccountRequest = new LinkAccountRequest();
    if (this.mTryInactiveAccounts)
    {
      localLinkAccountRequest.setSearchActiveOnly(false);
      this.mTryInactiveAccounts = false;
    }
    localLinkAccountRequest.setPublisher(this.mAccount.getPubId());
    localLinkAccountRequest.setUserUid(this.mAccount.getUserId());
    localLinkAccountRequest.setExternalPublisher(paramAccountInfo.getPubId());
    localLinkAccountRequest.setExternalUserUid(paramAccountInfo.getUserId());
    return localLinkAccountRequest;
  }

  public void run()
  {
    CurrencyRequestTask local1 = new CurrencyRequestTask(null, AccountInfoResponse.class)
    {
      protected String getDataToPost()
      {
        LinkAccountRequest localLinkAccountRequest = RequestLinkAccountRunnable.this.prepareRequest(RequestLinkAccountRunnable.this.mNewAccount);
        LoggerExt localLoggerExt = RequestLinkAccountRunnable.LOG;
        String str = RequestLinkAccountRunnable.TAG;
        Object[] arrayOfObject = new Object[2];
        arrayOfObject[0] = RequestLinkAccountRunnable.this.mAccount.getUserId();
        arrayOfObject[1] = RequestLinkAccountRunnable.this.mNewAccount.getUserId();
        localLoggerExt.logDebug(str, "Linking account {0} to account {1}", arrayOfObject);
        SecuredServiceRequest localSecuredServiceRequest = new SecuredRequestBuilder().setData(localLinkAccountRequest).buildLinkAccountRequest();
        RequestLinkAccountRunnable.LOG.logDebug(RequestLinkAccountRunnable.TAG, "LinkAccountsRequest object is : {0}", new Object[] { localLinkAccountRequest });
        setRequest(localSecuredServiceRequest);
        return super.getDataToPost();
      }
    };
    local1.setCallback(new LinkUserCallback(this.mAccount, this.mNewAccount)
    {
      public void onFailInBackground(AccountInfoResponse paramAnonymousAccountInfoResponse)
      {
        long l = this.mDelayTime.get();
        RequestLinkAccountRunnable.this.mUIHandler.postDelayed(RequestLinkAccountRunnable.this, 1000L * l);
        this.mDelayTime.set(2L * l);
      }

      public void onSuccessInBackground(AccountInfoResponse paramAnonymousAccountInfoResponse)
      {
        String str1 = paramAnonymousAccountInfoResponse.getStatusCode();
        if ("0".equals(str1))
        {
          AccountInfoResponse.AccountBean[] arrayOfAccountBean = paramAnonymousAccountInfoResponse.getAccounts();
          if ((arrayOfAccountBean == null) || (arrayOfAccountBean.length == 0))
          {
            RequestLinkAccountRunnable.this.mTryInactiveAccounts = true;
            onFailInBackground(paramAnonymousAccountInfoResponse);
            return;
          }
          super.onSuccessInBackground(paramAnonymousAccountInfoResponse);
          return;
        }
        if (!"2".equals(str1))
        {
          onFailInBackground(paramAnonymousAccountInfoResponse);
          return;
        }
        LoggerExt localLoggerExt = RequestLinkAccountRunnable.LOG;
        String str2 = RequestLinkAccountRunnable.TAG;
        Object[] arrayOfObject = new Object[1];
        arrayOfObject[0] = RequestLinkAccountRunnable.this.mNewAccount;
        localLoggerExt.logDebug(str2, "LinkAccountsRequest account not found on server : {0}", arrayOfObject);
      }
    });
    local1.execute(new Void[0]);
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.currency.request.RequestLinkAccountRunnable
 * JD-Core Version:    0.6.2
 */